home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / faxsetupdialog.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  8.1 KB  |  273 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2009 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Authors: Don Welch
  20. #
  21.  
  22. # StdLib
  23. import operator
  24.  
  25. # Local
  26. from base.g import *
  27. from base import device, utils
  28. from prnt import cups
  29. from base.codes import *
  30. from ui_utils import *
  31.  
  32. # Qt
  33. from PyQt4.QtCore import *
  34. from PyQt4.QtGui import *
  35.  
  36. # Ui
  37. from faxsetupdialog_base import Ui_Dialog
  38. from deviceuricombobox import DEVICEURICOMBOBOX_TYPE_FAX_ONLY
  39.  
  40. fax_enabled = prop.fax_build
  41.  
  42. if fax_enabled:
  43.     try:
  44.         from fax import fax
  45.     except ImportError:
  46.         # This can fail on Python < 2.3 due to the datetime module
  47.         # or if fax was diabled during the build
  48.         fax_enabled = False
  49.  
  50. if not fax_enabled:
  51.     log.error("Fax disabled.")
  52.  
  53.  
  54. class FaxSetupDialog(QDialog, Ui_Dialog):
  55.     def __init__(self, parent, device_uri):
  56.         QDialog.__init__(self, parent)
  57.         self.setupUi(self)
  58.         self.device_uri = device_uri
  59.         self.initUi()
  60.         self.dev = None
  61.         QTimer.singleShot(0, self.updateUi)
  62.  
  63.  
  64.     def initUi(self):
  65.         # connect signals/slots
  66.         self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
  67.         self.connect(self.FaxComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.FaxComboBox_noDevices)
  68.         self.connect(self.FaxComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.FaxComboBox_currentChanged)
  69.         self.FaxComboBox.setType(DEVICEURICOMBOBOX_TYPE_FAX_ONLY)
  70.  
  71.         # Application icon
  72.         self.setWindowIcon(QIcon(load_pixmap('prog', '48x48')))
  73.  
  74.         if self.device_uri:
  75.             self.FaxComboBox.setInitialDevice(self.device_uri)
  76.  
  77.         self.NameCompanyLineEdit.setMaxLength(50)
  78.         self.FaxNumberLineEdit.setMaxLength(50)
  79.         self.FaxNumberLineEdit.setValidator(PhoneNumValidator(self.FaxNumberLineEdit))
  80.         self.VoiceNumberLineEdit.setMaxLength(50)
  81.         self.VoiceNumberLineEdit.setValidator(PhoneNumValidator(self.VoiceNumberLineEdit))
  82.         self.EmailLineEdit.setMaxLength(50)
  83.  
  84.         self.connect(self.NameCompanyLineEdit, SIGNAL("editingFinished()"),
  85.                      self.NameCompanyLineEdit_editingFinished)
  86.  
  87.         self.connect(self.NameCompanyLineEdit, SIGNAL("textChanged(const QString &)"),
  88.                      self.NameCompanyLineEdit_textChanged)
  89.  
  90.         self.connect(self.FaxNumberLineEdit, SIGNAL("editingFinished()"),
  91.                      self.FaxNumberLineEdit_editingFinished)
  92.  
  93.         self.connect(self.FaxNumberLineEdit, SIGNAL("textChanged(const QString &)"),
  94.                      self.FaxNumberLineEdit_textChanged)
  95.  
  96.         self.connect(self.VoiceNumberLineEdit, SIGNAL("editingFinished()"),
  97.                      self.VoiceNumberLineEdit_editingFinished)
  98.  
  99.         self.connect(self.VoiceNumberLineEdit, SIGNAL("textChanged(const QString &)"),
  100.                      self.VoiceNumberLineEdit_textChanged)
  101.  
  102.         self.connect(self.EmailLineEdit, SIGNAL("editingFinished()"),
  103.                      self.EmailLineEdit_editingFinished)
  104.  
  105.         self.connect(self.EmailLineEdit, SIGNAL("textChanged(const QString &)"),
  106.                      self.EmailLineEdit_textChanged)
  107.  
  108.         self.name_company_dirty = False
  109.         self.fax_number_dirty = False
  110.         self.voice_number_dirty = False
  111.         self.email_dirty = False
  112.  
  113.  
  114.     def updateUi(self):
  115.         if not fax_enabled:
  116.             FailureUI(self, self.__tr("<b>PC send fax support is not enabled.</b><p>Re-install HPLIP with fax support or use the device front panel to send a fax.</p><p>Click <i>OK</i> to exit.</p>"))
  117.             self.close()
  118.             return
  119.  
  120.         self.FaxComboBox.updateUi()
  121.  
  122.  
  123.     def FaxComboBox_currentChanged(self, device_uri):
  124.         self.device_uri = device_uri
  125.         self.updateCoverpageTab()
  126.  
  127.         if self.dev is not None:
  128.             self.dev.close()
  129.  
  130.         try:
  131.             self.dev = fax.getFaxDevice(self.device_uri)
  132.         except Error:
  133.             CheckDeviceUI(self)
  134.             return
  135.  
  136.         self.updateHeaderTab()
  137.  
  138.  
  139.  
  140.     def FaxComboBox_noDevices(self):
  141.         FailureUI(self, self.__tr("<b>No devices that require fax setup found.</b>"))
  142.         self.close()
  143.  
  144.     #
  145.     # Name/Company (for TTI header) (stored in device)
  146.     #
  147.  
  148.     def NameCompanyLineEdit_editingFinished(self):
  149.         self.saveNameCompany(unicode(self.NameCompanyLineEdit.text()))
  150.  
  151.  
  152.     def NameCompanyLineEdit_textChanged(self, s):
  153.         self.name_company_dirty = True
  154.  
  155.  
  156.     def saveNameCompany(self, s):
  157.         self.name_company_dirty = False
  158.         beginWaitCursor()
  159.         try:
  160.             try:
  161.                 log.debug("Saving station name %s to device" % s)
  162.                 self.dev.setStationName(s)
  163.             except Error:
  164.                 CheckDeviceUI()
  165.         finally:
  166.             endWaitCursor()
  167.  
  168.     #
  169.     # Fax Number (for TTI header) (stored in device)
  170.     #
  171.  
  172.     def FaxNumberLineEdit_editingFinished(self):
  173.         self.saveFaxNumber(unicode(self.FaxNumberLineEdit.text()))
  174.  
  175.  
  176.     def FaxNumberLineEdit_textChanged(self, s):
  177.         self.fax_number_dirty = True
  178.  
  179.  
  180.     def saveFaxNumber(self, s):
  181.         self.fax_number_dirty = False
  182.         beginWaitCursor()
  183.         try:
  184.             try:
  185.                 log.debug("Saving fax number %s to device" % s)
  186.                 self.dev.setPhoneNum(s)
  187.             except Error:
  188.                 CheckDeviceUI()
  189.         finally:
  190.             endWaitCursor()
  191.  
  192.     #
  193.     # Voice Number (for coverpage) (stored in ~/.hplip/hplip.conf)
  194.     #
  195.  
  196.     def VoiceNumberLineEdit_editingFinished(self):
  197.         self.saveVoiceNumber(unicode(self.VoiceNumberLineEdit.text()))
  198.  
  199.  
  200.     def VoiceNumberLineEdit_textChanged(self, s):
  201.         self.voice_number_dirty = True
  202.  
  203.  
  204.     def saveVoiceNumber(self, s):
  205.         log.debug("Saving voice number (%s) to ~/.hplip/hplip.conf" % s)
  206.         self.voice_number_dirty = False
  207.         user_conf.set('fax', 'voice_phone', s)
  208.  
  209.     #
  210.     # EMail (for coverpage) (stored in ~/.hplip/hplip.conf)
  211.     #
  212.  
  213.     def EmailLineEdit_editingFinished(self):
  214.         self.saveEmail(unicode(self.EmailLineEdit.text()))
  215.  
  216.  
  217.     def EmailLineEdit_textChanged(self, s):
  218.         self.email_dirty = True
  219.  
  220.  
  221.     def saveEmail(self, s):
  222.         log.debug("Saving email address (%s) to ~/.hplip/hplip.conf" % s)
  223.         self.email_dirty = False
  224.         user_conf.set('fax', 'email_address', s)
  225.  
  226.     #
  227.     #
  228.     #
  229.  
  230.     def CancelButton_clicked(self):
  231.         self.close()
  232.  
  233.  
  234.     def updateHeaderTab(self):
  235.         beginWaitCursor()
  236.         try:
  237.             try:
  238.                 name_company = self.dev.getStationName()
  239.                 self.NameCompanyLineEdit.setText(name_company)
  240.  
  241.                 fax_number = self.dev.getPhoneNum()
  242.                 self.FaxNumberLineEdit.setText(fax_number)
  243.             except Error:
  244.                 CheckDeviceUI()
  245.         finally:
  246.             endWaitCursor()
  247.  
  248.  
  249.     def updateCoverpageTab(self):
  250.         self.VoiceNumberLineEdit.setText(user_conf.get('fax', 'voice_phone'))
  251.         self.EmailLineEdit.setText(user_conf.get('fax', 'email_address'))
  252.  
  253.  
  254.     def closeEvent(self, e):
  255.         if self.voice_number_dirty:
  256.             self.VoiceNumberLineEdit.emit(SIGNAL("editingFinished()"))
  257.         if self.name_company_dirty:
  258.             self.NameCompanyLineEdit.emit(SIGNAL("editingFinished()"))
  259.         if self.email_dirty:
  260.             self.EmailLineEdit.emit(SIGNAL("editingFinished()"))
  261.         if self.fax_number_dirty:
  262.             self.FaxNumberLineEdit.emit(SIGNAL("editingFinished()"))
  263.         e.accept()
  264.  
  265.     #
  266.     # Misc
  267.     #
  268.  
  269.     def __tr(self,s,c = None):
  270.         return qApp.translate("FaxSetupDialog",s,c)
  271.  
  272.  
  273.